//
//  ViewController.m
//  10-tableViewCell-custom
//
//  Created by 王道林 on 16/7/27.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "ViewController.h"
#import "CustomTableViewCell.h"
#import "CustomTwoTableViewCell.h"
#import "NewsObject.h"

@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableview;
@property (nonatomic, strong) NSMutableArray *marr;
@property (nonatomic, strong) NSMutableArray *marrModel;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self createData];
    [self createSubView];
}

- (void)createData
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"DLS160710" ofType:@"plist"];
    NSArray *arr = [NSArray arrayWithContentsOfFile:path];
    _marr = [NSMutableArray arrayWithArray:arr];
    NSLog(@"%@",_marr);
    
    // 1 数据的传递依赖于Model . 传对象存对象取对象
    NewsObject *newsObj1 = [[NewsObject alloc] initWithNewsImage:@"4" NewsTitle:@"苍老师" NewsDescription:@"王黄爱上苍老师" newsNumber:@"无数人跟帖"];
    _marrModel = @[newsObj1, newsObj1, newsObj1, newsObj1].mutableCopy;
    
    
}


- (void)createSubView
{
    _tableview = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    [self.view addSubview:_tableview];
    [_tableview registerClass:[CustomTwoTableViewCell class] forCellReuseIdentifier:@"wang"];
    
    self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    //  多种cell 混合使用
    //  再注册一个cell ... 重用标识不要一样
    
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];
    [_tableview setEditing:editing animated:animated];
}




- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _marrModel.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CustomTwoTableViewCell *cell = [_tableview dequeueReusableCellWithIdentifier:@"wang" forIndexPath:indexPath];
//    cell.textLabel.text = _marr[indexPath.row][@"name"];
    
    cell.newsObject = _marrModel[indexPath.row];
    return cell;
}


//

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 200;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
